﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Xml;
using System.Net.Mail;
using System.Net;

namespace Web
{
    /// <summary>
    /// CommFun 的摘要说明
    /// </summary>
    public class CommFun
    {
        public CommFun()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        private static byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };

        #region DES加密字符串
        /// <summary>
        /// DES加密字符串
        /// </summary>
        /// <param name="encryptString">待加密的字符串</param>
        /// <param name="encryptKey">加密密钥,要求必须刚好为8位，不然运行不正确</param>
        /// <returns>加密成功返回加密后的字符串，失败返回源串</returns>
        public static string EncryptDES(string encryptString, string encryptKey)
        {
            try
            {
                byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
                byte[] rgbIV = Keys;
                byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
                DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
                MemoryStream mStream = new MemoryStream();
                CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
                cStream.Write(inputByteArray, 0, inputByteArray.Length);
                cStream.FlushFinalBlock();
                return Convert.ToBase64String(mStream.ToArray());
            }
            catch (Exception e1)
            {
                System.Console.WriteLine(e1.Message);
                return encryptString;
            }
        }

        #endregion

        #region DES解密字符串
        /// <summary>
        /// DES解密字符串
        /// </summary>
        /// <param name="decryptString">待解密的字符串</param>
        /// <param name="decryptKey">解密密钥,,要求必须刚好为8位，不然运行不正确,和加密密钥相同</param>
        /// <returns>解密成功返回解密后的字符串，失败返源串</returns>
        public static string DecryptDES(string decryptString, string decryptKey)
        {
            try
            {
                byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey);
                byte[] rgbIV = Keys;
                byte[] inputByteArray = Convert.FromBase64String(decryptString);
                DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider();
                MemoryStream mStream = new MemoryStream();
                CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
                cStream.Write(inputByteArray, 0, inputByteArray.Length);
                cStream.FlushFinalBlock();
                return Encoding.UTF8.GetString(mStream.ToArray());
            }
            catch (Exception e1)
            {
                System.Console.WriteLine(e1.Message);
                return decryptString;
            }
        }
        #endregion

        #region 站点配置
        public static string xmlread(int i)
        {

            string url = System.Web.HttpContext.Current.Server.MapPath("user.xml");//获得当前文件夹下的XML文件
            StreamReader sRead = new StreamReader(url, System.Text.Encoding.GetEncoding("GB2312"));//以一种特定的编码从字节流读取字符,必须要转化成GB2312读取才不能出乱码
            XmlDataDocument datadoc = new XmlDataDocument();//操作XML文档
            datadoc.DataSet.ReadXml(sRead);//将读取的字节流存到DataSet里面去
            sRead.Close();//关闭字节流的读取
            return datadoc.DataSet.Tables[0].Rows[0][i].ToString(); 
            datadoc = null;//清空对XML数据的操作

        }
        #endregion

        #region 上传图片方法
        //上传图片方法
        public static string upload(FileUpload fup)
        {
            System.Threading.Thread.Sleep(100);
            String filename = DateTime.Now.ToString("yyyyMMddHHmissffff") + System.IO.Path.GetExtension(fup.FileName).ToLower();
            String inpath = "../../UploadFiles/" + filename.ToString();
            filename = System.Web.HttpContext.Current.Server.MapPath("../../UploadFiles/") + filename;
            if (fup.HasFile)
            {
                if (fup.PostedFile.ContentLength < (3072 * 1024))
                {
                        fup.SaveAs(filename);
                }
            }
            else
            {
                inpath = "";
            }
            return inpath.ToString();
        }
        #endregion

        #region 防url注入
        public static void sqlzy()
        {
            
                string sqlzy = HttpContext.Current.Request.Url.ToString();
                string Illegal_Str = "select|delete|update|insert|where|and|*|%|,|+|'|\"|";
                string[] newstr = Illegal_Str.Split('|');
                for (int i = 0; i < (newstr.Length - 1); i++)
                {
                    if (sqlzy.IndexOf(newstr[i]) != -1)
                    {
                        System.Web.HttpContext.Current.Response.Write("<script>alert('含有非法字符，我们正在与110联系！');history.back()</script>");
                    }
                }
        }
        #endregion

        #region 获取int传参是否正确，如果返回0刚不正确，特殊情况就是传0也是返回0
        /// <summary>
        /// 获取int传参是否正确，如果返回0刚不正确，特殊情况就是传0也是返回0
        /// </summary>
        /// <returns></returns>
        public static int GetIntUrl(string strUrl)
        {
            string strTrueUrl = System.Web.HttpContext.Current.Request.QueryString[strUrl];
            if (strTrueUrl == null)
                return 0;
            if (strTrueUrl.ToString().Trim() == "")
                return 0;
            try
            {
                return int.Parse(strTrueUrl.ToString().Trim());
            }
            catch
            {
                return 0;
            }
        }
        #endregion

        #region 获取int传参是否正确
        public static bool GetInt(string strid)
        {
            try
            {
                 Convert.ToInt32(strid.Trim());
                 return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region  查询是否含有SQL注入漏洞的字符，如果有，返回true
        /// <summary>
        /// 查询是否含有SQL注入漏洞的字符，如果有，返回true
        /// 关于正则表达式，请参见http://www.xfocus.net/articles/200508/816.html
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string HasSqlInjectionChar(string str)
        {
            //检测SQL meta-characters的正则表达式
            //检查单引号等值的hex，单引号本身或者双重扩折号。这些是MS SQL Server或Oracle的字符, 表示后边的为评论, 随后的都将被忽略。 
            str = Regex.Replace(str, @"/(\%27)|(\')|(\-\-)|(\%23)|(#)/ix", "");//指示正则表达式在输入字符串中是否找到匹配项。
            //修正检测SQL meta-characters的正则表达式
            //这个规则首先留意 = 号或它的hex值(%3D)，然后考虑零个或多个除换行符以外的任意字符，最后检测单引号，双重破折号或分号。
            str = Regex.Replace(str, @"/((\%3D)|(=))[^\n]*((\%27)|(\')|(\-\-)|(\%3B)|(;))/i", "");
            //典型的 SQL 注入攻击的正则表达式
            //\w* - 零个或多个字符或者下划线。
            //(\%27)|\' - 单引号或它的hex等值。
            //(\%6 F)|o|(\%4 F))((\%72)|r|-(\%52) －‘or’的大小写以及它的hex等值。
            str = Regex.Replace(str, @"/\w*((\%27)|(\'))((\%6F)|o|(\%4F))((\%72)|r|(\%52))/ix", "");
            //检测SQL注入，UNION查询关键字的正则表达式
            str = Regex.Replace(str, @"/((\%27)|(\'))union/ix", "");

            //检测MS SQL Server SQL注入攻击的正则表达式
            //exec - 请求执行储存或扩展储存过程的关键字
            //(\s|\+)+ - 一个或多个的空白或它们的http等值编码
            //(s|x) p- ‘sp’或‘xp'字母用来辨认储存或扩展储存过程
            //\w+ - 一个或多个字符或下划线来匹配过程的名称
            str = Regex.Replace(str, @"/exec(\s|\+)+(s|x)p\w+/ix", "");

            return str;
        }
        #endregion

        #region  查询是否含有SQL注入漏洞的字符，如果有，返回true
        /// <summary>
        /// 查询是否含有SQL注入漏洞的字符，如果有，返回true
        /// 关于正则表达式，请参见http://www.xfocus.net/articles/200508/816.html
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static void HasSqlInjectionChar(Page page)
        {
            foreach (Control control in page.Form.Controls)
            {
                if (control.GetType().Name == "TextBox")
                {
                    TextBox txtModle = new TextBox();
                    txtModle = (TextBox)page.FindControl(control.ID);
                    //单引号替换成两个单引号
                    txtModle.Text = txtModle.Text.Replace("'", "’");
                    txtModle.Text = txtModle.Text.Replace("update", "");
                    txtModle.Text = txtModle.Text.Replace("select", "");
                    txtModle.Text = txtModle.Text.Replace("delect", "");
                    txtModle.Text = txtModle.Text.Replace("insert", "");
                    txtModle.Text = txtModle.Text.Replace("and", "");
                    txtModle.Text = txtModle.Text.Replace("where", "");
                    txtModle.Text = txtModle.Text.Replace("or", "");
                    txtModle.Text = txtModle.Text.Replace("*", "");
                    //半角封号替换为全角封号，防止多语句执行
                    txtModle.Text = txtModle.Text.Replace(";", "；");
                    //半角括号替换为全角括号
                    txtModle.Text = txtModle.Text.Replace("(", "（");
                    txtModle.Text = txtModle.Text.Replace(")", "）");
                    ///////////////要用正则表达式替换，防止字母大小写得情况////////////////////
                    //去除执行存储过程的命令关键字
                    txtModle.Text = txtModle.Text.Replace("Exec", "");
                    txtModle.Text = txtModle.Text.Replace("Execute", "");
                    //去除系统存储过程或扩展存储过程关键字
                    txtModle.Text = txtModle.Text.Replace("xp_", "x p_");
                    txtModle.Text = txtModle.Text.Replace("sp_", "s p_");
                    //防止16进制注入
                    txtModle.Text = txtModle.Text.Replace("0x", "0 x");
                }
            }
        }
        #endregion

        #region 验证码
        /// <summary>
        /// 验证码
        /// </summary>
        /// <param name="n">验证码的个数</param>
        /// <returns>返回生成的随机数</returns>
        public static string RandomNum(int n) //
        {
            string strchar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
            string[] VcArray = strchar.Split(',');
            string VNum = "";                    //
            int temp = -1;                       //记录上次随机数值，尽量避免产生几个一样的随机数
            //采用一个简单的算法以保证生成随机数的不同
            Random rand = new Random();
            for (int i = 1; i < n + 1; i++)
            {
                if (temp != -1)
                {
                    rand = new Random(i * temp * unchecked((int)DateTime.Now.Ticks));
                }
                int t = rand.Next(61);
                if (temp != -1 && temp == t)
                {
                    return RandomNum(n);
                }
                temp = t;
                VNum += VcArray[t];
            }
            return VNum;//返回生成的随机数
        }

        #endregion

        #region 取得自定义长度的字符串
        //中英文混合的字符串，在截取后，长度要一致，即8个字节的长度(不包括三个点)，而且不能出现中文被从中间截断的情况
        public static string getStr(string str, int strLength)
        {
            ASCIIEncoding n = new ASCIIEncoding();
            byte[] b = n.GetBytes(str);
            int l = 0; // l 为字符串之实际长度
            for (int i = 0; i <= b.Length - 1; i++)
            {
                if (b[i] == 63) //判断是否为汉字或全脚符号 
                {
                    l += 2;
                    if (l > strLength)
                        return str.Substring(0, l - 4) + "...";
                }
                else
                {
                    l++;
                    if (l > strLength)
                        return str.Substring(0, l - 4) + "...";
                }

            }
            return str;

        }

        public static string CutChar(string strChar, int intLength,int ys)
        {
            //取得自定义长度的字符串
            if (strChar.Length > intLength)
            {
                if (ys == 1)
                {
                    return strChar.Substring(0, intLength) + "...";
                }
                else
                {
                    return strChar.Substring(0, intLength);
                }
            }
            else
            { return strChar; }

        }

        public static string GetLimitChar(string txt, int lenght)
        {
            //取得自定义长度的字符串  中文123456789           
            string outputtext = "";
            if (txt.Length > lenght)
            {
                //int tempnum = 0;
                int tempnum1 = 0;
                int tempnum2 = 0;
                byte[] byitem = System.Text.ASCIIEncoding.ASCII.GetBytes(txt);
                for (int i = 0; i < txt.Length; i++)
                {
                    if ((int)byitem[i] != 63) tempnum1++; else tempnum2++;
                    if (tempnum2 * 2 + tempnum1 >= lenght * 2) break;
                }
                outputtext = txt.Substring(0, tempnum2 + tempnum1);
            }
            else
            {
                outputtext = txt;
            }
            return outputtext;
        }

        public static string cutTitle(string str, int len)
        {
            int intLen = str.Length;
            int start = 0;
            int end = intLen;
            int single = 0;
            char[] chars = str.ToCharArray();
            for (int i = 0; i < chars.Length; i++)
            {
                if (Convert.ToInt32(chars[i]) > 255)
                {
                    start += 2;
                }
                else
                {
                    start += 1;
                    single++;
                }
                if (start >= len)
                {

                    if (end % 2 == 0)
                    {
                        if (single % 2 == 0)
                        {
                            end = i + 1;
                        }
                        else
                        {
                            end = i;
                        }
                    }
                    else
                    {
                        end = i + 1;
                    }
                    break;
                }
            }
            string temp = str.Substring(0, end);
            if (str.Length > end)
            {
                return temp + "...";
            }
            else
            {
                return temp;
            }
        }

        #endregion

        #region      数据备份
        public static bool dbbeifeng(string oldDB, string newDB, string Ope)
        {
            if (Ope == "bf")//备份
            {
                FileInfo dataFile = new FileInfo(System.Web.HttpContext.Current.Server.MapPath(@"~/App_Data/") + newDB);
                dataFile.CopyTo(System.Web.HttpContext.Current.Server.MapPath(@"~/backup/") + oldDB, true);
                return true;
            }
            else if (Ope == "hy")//还原
            {
                FileInfo dataFile = new FileInfo(System.Web.HttpContext.Current.Server.MapPath(@"~/backup/") + oldDB);
                dataFile.CopyTo(System.Web.HttpContext.Current.Server.MapPath(@"~/App_Data/") + newDB, true);
                return true;
            }
            else
            {
                return false;
            }
        }

        #endregion

        #region 判断是否为正确的 email 地址格式 public static bool IsEmail(string s)
        /// <summary>
        /// 判断是否为正确的 email 地址格式
        /// </summary>
        public static bool IsEmail(string s)
        {
            string pattern = @"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$";
            return Regex.IsMatch(s, pattern);
        }
        #endregion

        #region 没有登录或登录超时

        public static void IsAdmin()
        {

            //查看是否为超级管理员
            if (HttpContext.Current.Session["Admin"] != null)
            {

                if (HttpContext.Current.Session["Admin"].ToString() != "yes")
                {
                    HttpContext.Current.Response.Write(@"<script>alert('你还没有登录或登录超时！');window.location.href='../index.aspx';</script>");
                }
            }
            else {HttpContext.Current.Response.Write(@"<script>alert('你还没有登录或登录超时！');window.location.href='../index.aspx';</script>"); }

        }

        public static void IsAdmin1()
        {
            //查看是否为超级管理员
            if (HttpContext.Current.Session["Admin"] != null)
            {

                if (HttpContext.Current.Session["Admin"].ToString() != "yes")
                {
                    HttpContext.Current.Response.Write(@"<script>alert('你还没有登录或登录超时！');window.location.href='index.aspx';</script>");
                }
            }
            else { HttpContext.Current.Response.Write(@"<script>alert('你还没有登录或登录超时！');window.location.href='index.aspx';</script>"); }

        }
       #endregion

        #region 过滤内容中的'，"，+为全角
        /// <summary>
        /// 过滤内容中的'，"，+为全角
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string Nostr(string str)
        {
            String nstr = str.Replace("'", "＇").Replace("+", "＋").Replace("\"", "＂");
            return nstr;
        }
        #endregion

        #region 提示错误信息！操作回滚！
        /// <summary>
        /// 提示错误信息！操作回滚！
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="code"></param>
        public static void Show_Msg(string msg)
        {
            HttpContext.Current.Response.Write("<script>alert(\"" + msg + "\");history.back();</script>");
        }
        #endregion

        #region 提示成功信息！转向！
        /// <summary>
        /// 提示成功信息！转向！
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="url"></param>
        public static void Show_Msg(string msg, string url)
        {
            HttpContext.Current.Response.Write("<script>alert(\"" + msg + "\");location.href='" + url + "';</script>");
        }

        #endregion

        #region 提示转向！
        /// <summary>
        /// 转向！
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="url"></param>
        public static void Show_Msg(string url,int i)
        {
            HttpContext.Current.Response.Write("<script>window.location.href='" + url + "';</script>");
        }
        #endregion

        #region 打开指定大小位置的模式对话框
        /// </summary>
        /// <param name="url"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="top"></param>
        /// <param name="left"></param>
        public static void ShowModalDialog(string url, int width, int height, int top, int left)
        {
            string features = "dialogWidth:" + width.ToString() + "px"
                + ";dialogHeight:" + height.ToString() + "px"
                + ";dialogLeft:" + left.ToString() + "px"
                + ";dialogTop:" + top.ToString() + "px"
                + ";center:yes;help=no;resizable:no;status:no;scroll=yes";
            string js = @"<script language=javascript>							
							showModalDialog('" + url + "','','" + features + "');</script>";
            HttpContext.Current.Response.Write(js);
        }
        #endregion

        #region 除去内容中的html代码
        public static string DealHtml(string str)
        {
            str = Regex.Replace(str, @"\<(img)[^>]*>|<\/(img)>", "", RegexOptions.IgnoreCase);
            str = Regex.Replace(str, @"\<(table|tbody|tr|td|th|)[^>]*>|<\/(table|tbody|tr|td|th|)>", "", RegexOptions.IgnoreCase);
            str = Regex.Replace(str, @"\<(div|blockquote|fieldset|legend)[^>]*>|<\/(div|blockquote|fieldset|legend)>", "", RegexOptions.IgnoreCase);
            str = Regex.Replace(str, @"\<(font|i|u|h[1-9]|s)[^>]*>|<\/(font|i|u|h[1-9]|s)>", "", RegexOptions.IgnoreCase);
            str = Regex.Replace(str, @"\<(style|strong)[^>]*>|<\/(style|strong)>", "", RegexOptions.IgnoreCase);
            str = Regex.Replace(str, @"\<a[^>]*>|<\/a>", "", RegexOptions.IgnoreCase);
            str = Regex.Replace(str, @"\<(meta|iframe|frame|span|tbody|layer)[^>]*>|<\/(iframe|frame|meta|span|tbody|layer)>", "", RegexOptions.IgnoreCase);
            str = Regex.Replace(str, @"\<a[^>]*", "", RegexOptions.IgnoreCase);
            return str;
        }
        #endregion

        #region  替换html中的特殊字符
        /// <summary>
        /// 替换html中的特殊字符
        /// </summary>
        /// <param name="theString">需要进行替换的文本。</param>
        /// <returns>替换完的文本。</returns>
        public static string HtmlEncode(string theString)
        {
            theString = theString.Replace(">", "&gt;");
            theString = theString.Replace("<", "&lt;");
            theString = theString.Replace("  ", " &nbsp;");
            theString = theString.Replace("  ", " &nbsp;");
            theString = theString.Replace("\"", "&quot;");
            theString = theString.Replace("\'", "&#39;");
            theString = theString.Replace("\n", "<br/> ");
            return theString;
        }

        #endregion

        #region  恢复html中的特殊字符
        /// <summary>
        /// 恢复html中的特殊字符
        /// </summary>
        /// <param name="theString">需要恢复的文本。</param>
        /// <returns>恢复好的文本。</returns>
        public static string HtmlDiscode(string theString)
        {
            theString = theString.Replace("&gt;", ">");
            theString = theString.Replace("&lt;", "<");
            theString = theString.Replace("&nbsp;", " ");
            theString = theString.Replace(" &nbsp;", "  ");
            theString = theString.Replace("&quot;", "\"");
            theString = theString.Replace("&#39;", "\'");
            theString = theString.Replace("<br/> ", "\n");
            return theString;
        }

        #endregion

        #region 发送mail
        //  sendMail("订单通知", "" + dr[2].ToString() + "您好：<br/>您的订单" + dr[1].ToString() + "中的商品已于" + DateTime.Now.ToString() + "发出，请注意查收。<br><br><br>mstyle.cn创意网<br>联系我们：021-54047855  marketing@mstyle.cn ", dr[5].ToString(), "zhangzhiqiang213@163.com", "zhangzhiqiang213", "07988506977", "smtp.163.com");      
        public static void sendMail(string title, string body, string toAdress, string fromAdress, string userName, string userPwd, string smtpHost)
        {
            try
            {
                MailAddress to = new MailAddress(toAdress);
                MailAddress from = new MailAddress(fromAdress);
                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);
                message.Subject = title;
                message.Body = body;
                SmtpClient smtp = new SmtpClient();
                smtp.UseDefaultCredentials = true;
                smtp.Port = 25;
                smtp.Credentials = new NetworkCredential(userName, userPwd);
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtp.Host = smtpHost;
                message.To.Add(toAdress);
                message.BodyEncoding = System.Text.Encoding.UTF8;
                message.IsBodyHtml = true;
                message.Priority = MailPriority.Normal;
                smtp.Send(message);
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex.Message);

            }
        }
        #endregion

        #region 返回ToDate减去FromDate后的时间单位数量，根据DatePart参数可能是年、月、日、时、分、秒
        /// <summary>
        /// 返回ToDate减去FromDate后的时间单位数量，根据DatePart参数可能是年、月、日、时、分、秒  string  cc="2009-7-24 16:47:30";
        /// Response.Write(Web.CommFun.DateDiff(Convert.ToDateTime(cc),System.DateTime.Now,"mi"));
        /// </summary>
        /// <param name="FromDate">减数时间</param>
        /// <param name="ToDate">被减数时间</param>
        /// <param name="DatePart">差的单位：yy，mm，dd, hh, mi, ss</param>
        /// <returns>ToDate减去FromDate后的时间单位数量，根据DatePart参数可能是年、月、日、时、分、秒</returns>
        public static double DateDiff(DateTime FromDate, DateTime ToDate, string DatePart)
        {
            TimeSpan ts = new TimeSpan();
            double Year = 0;
            double Month = 0;
            ts = ToDate - FromDate;
            switch (DatePart)
            {
                case "ss":
                    {
                        return ts.TotalSeconds;
                    }
                case "mi":
                    {
                        return ts.TotalMinutes;
                    }
                case "hh":
                    {
                        return ts.TotalHours;
                    }
                case "dd":
                    {
                        return ts.TotalDays;
                    }
                case "mm":
                    {
                        Year = ToDate.Year - FromDate.Year;
                        Month = ToDate.Month - FromDate.Month;
                        return Year * 12 + Month;
                    }
                case "yy":
                    {
                        Year = ToDate.Year - FromDate.Year;
                        return Year;
                    }
                default:
                    {
                        throw new Exception("请输入正确的时间单位字符串！");
                    }
            }
        }
        #endregion

        #region 内容分页

        // content1 = dt1.Rows[0]["contents"].ToString().Replace("<input", "<img");
        // int page = Convert.ToInt32(Request.QueryString["page"]); 
        // GetNews(content1, page);

        //public static void GetNews(string strNews, int page,)
        //{
        //    string[] temp = strNews.Split('^'); //取的分页符
        //    if (temp.Length <= 1)
        //    {
        //        content.Text = strNews; //文章内容
        //    }
        //    else
        //    {
        //        lbpage.Text = "共" + temp.Length + "页&nbsp;&nbsp;";

        //        for (int i = 0; i < temp.Length; i++)
        //        {
        //            lbpage.Text += ("[<a href =?page=" + i + ">" + (i + 1) + "</a>]&nbsp;&nbsp;");
        //        }
        //        content.Text = temp[page].ToString();
        //    }

        //}

        #endregion

        #region 备用
        //public static string alertChk(string str, int how)
        //{
        //    switch (how)
        //    {
        //        case 1:
        //            return "<script>alert('" + str + "');window.location.href='Default.aspx'</script>";
        //        case 2:
        //            return "<script>alert('" + str + "');window.close()</script>";
        //        default:
        //            return "<script>alert('" + str + "');history.go(-1)</script>";
        //    }
        //}
        #endregion

    }
}